<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>palette.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_ui_equation_palette.js.html">palette.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2009 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview A palette of icons.
<a name="line17"></a> * The icons are generated from a single sprite image that
<a name="line18"></a> * is used for multiple palettes.
<a name="line19"></a> * All icons of a single palette must be on the same sprite row
<a name="line20"></a> * (same y coordinate) and all have the same width.
<a name="line21"></a> * Each item has an associated action command that should be taken
<a name="line22"></a> * when certain event is dispatched.
<a name="line23"></a> *
<a name="line24"></a> */
<a name="line25"></a>
<a name="line26"></a>goog.provide(&#39;goog.ui.equation.Palette&#39;);
<a name="line27"></a>goog.provide(&#39;goog.ui.equation.PaletteEvent&#39;);
<a name="line28"></a>goog.provide(&#39;goog.ui.equation.PaletteRenderer&#39;);
<a name="line29"></a>
<a name="line30"></a>goog.require(&#39;goog.dom&#39;);
<a name="line31"></a>goog.require(&#39;goog.dom.TagName&#39;);
<a name="line32"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line33"></a>goog.require(&#39;goog.ui.Palette&#39;);
<a name="line34"></a>goog.require(&#39;goog.ui.PaletteRenderer&#39;);
<a name="line35"></a>
<a name="line36"></a>
<a name="line37"></a>
<a name="line38"></a>/**
<a name="line39"></a> * Constructs a new palette.
<a name="line40"></a> * @param {goog.ui.equation.PaletteManager} paletteManager The
<a name="line41"></a> *     manager of the palette.
<a name="line42"></a> * @param {goog.ui.equation.Palette.Type} type The type of the
<a name="line43"></a> *     palette.
<a name="line44"></a> * @param {number} spriteX Coordinate of first icon in sprite.
<a name="line45"></a> * @param {number} spriteY Coordinate of top of all icons in sprite.
<a name="line46"></a> * @param {number} itemWidth Pixel width of each palette icon.
<a name="line47"></a> * @param {number} itemHeight Pixel height of each palette icon.
<a name="line48"></a> * @param {Array.&lt;string&gt;=} opt_actions An optional action list for palette
<a name="line49"></a> *     elements. The number of actions determine the number of palette
<a name="line50"></a> *     elements.
<a name="line51"></a> * @param {goog.ui.PaletteRenderer=} opt_renderer Optional customized renderer,
<a name="line52"></a> *     defaults to {@link goog.ui.PaletteRenderer}.
<a name="line53"></a> * @extends {goog.ui.Palette}
<a name="line54"></a> * @constructor
<a name="line55"></a> */
<a name="line56"></a>goog.ui.equation.Palette = function(paletteManager, type, spriteX,
<a name="line57"></a>    spriteY, itemWidth, itemHeight, opt_actions, opt_renderer) {
<a name="line58"></a>
<a name="line59"></a>  /**
<a name="line60"></a>   * The type of the palette.
<a name="line61"></a>   * @type {goog.ui.equation.Palette.Type}
<a name="line62"></a>   * @private
<a name="line63"></a>   */
<a name="line64"></a>  this.type_ = type;
<a name="line65"></a>
<a name="line66"></a>  /**
<a name="line67"></a>   * The palette actions.
<a name="line68"></a>   * @type {Array.&lt;string&gt;}
<a name="line69"></a>   * @private
<a name="line70"></a>   */
<a name="line71"></a>  this.actions_ = opt_actions || [];
<a name="line72"></a>
<a name="line73"></a>  var renderer =
<a name="line74"></a>      opt_renderer ||
<a name="line75"></a>      goog.ui.equation.PaletteRenderer.getInstance();
<a name="line76"></a>
<a name="line77"></a>  // Create a div element for each icon.
<a name="line78"></a>  var elements = [];
<a name="line79"></a>  var x = - spriteX;
<a name="line80"></a>  var y = - spriteY;
<a name="line81"></a>  for (var i = 0; i &lt; opt_actions.length; i++) {
<a name="line82"></a>    elements.push(paletteManager.getDomHelper().createDom(
<a name="line83"></a>        goog.dom.TagName.DIV,
<a name="line84"></a>        {&#39;class&#39;: renderer.getItemCssClass(),
<a name="line85"></a>          &#39;style&#39;: &#39;width:&#39; + itemWidth +
<a name="line86"></a>              &#39;px;height:&#39; + itemHeight +
<a name="line87"></a>              &#39;px;&#39; +
<a name="line88"></a>              &#39;background-position:&#39; +
<a name="line89"></a>              x + &#39;px &#39; + y + &#39;px;&#39;}));
<a name="line90"></a>    x -= itemWidth;
<a name="line91"></a>  }
<a name="line92"></a>
<a name="line93"></a>  /**
<a name="line94"></a>   * The palette manager that manages all the palettes.
<a name="line95"></a>   * @type {goog.ui.equation.PaletteManager}
<a name="line96"></a>   * @private
<a name="line97"></a>   */
<a name="line98"></a>  this.paletteManager_ = paletteManager;
<a name="line99"></a>
<a name="line100"></a>  goog.ui.Palette.call(this, elements, renderer, paletteManager.getDomHelper());
<a name="line101"></a>};
<a name="line102"></a>goog.inherits(goog.ui.equation.Palette, goog.ui.Palette);
<a name="line103"></a>
<a name="line104"></a>
<a name="line105"></a>/**
<a name="line106"></a> * The type of possible palettes. They are made short to minimize JS size.
<a name="line107"></a> * @enum {string}
<a name="line108"></a> */
<a name="line109"></a>goog.ui.equation.Palette.Type = {
<a name="line110"></a>  MENU: &#39;mn&#39;,
<a name="line111"></a>  GREEK: &#39;g&#39;,
<a name="line112"></a>  SYMBOL: &#39;s&#39;,
<a name="line113"></a>  COMPARISON: &#39;c&#39;,
<a name="line114"></a>  MATH: &#39;m&#39;,
<a name="line115"></a>  ARROW: &#39;a&#39;
<a name="line116"></a>};
<a name="line117"></a>
<a name="line118"></a>
<a name="line119"></a>/**
<a name="line120"></a> * The CSS class name for the palette.
<a name="line121"></a> * @type {string}
<a name="line122"></a> */
<a name="line123"></a>goog.ui.equation.Palette.CSS_CLASS = &#39;ee-palette&#39;;
<a name="line124"></a>
<a name="line125"></a>
<a name="line126"></a>/**
<a name="line127"></a> * Returns the type of the palette.
<a name="line128"></a> * @return {goog.ui.equation.Palette.Type} The type of the palette.
<a name="line129"></a> */
<a name="line130"></a>goog.ui.equation.Palette.prototype.getType = function() {
<a name="line131"></a>  return this.type_;
<a name="line132"></a>};
<a name="line133"></a>
<a name="line134"></a>
<a name="line135"></a>/**
<a name="line136"></a> * Returns the palette manager.
<a name="line137"></a> * @return {goog.ui.equation.PaletteManager} The palette manager
<a name="line138"></a> *     that manages all the palette.
<a name="line139"></a> */
<a name="line140"></a>goog.ui.equation.Palette.prototype.getPaletteManager = function() {
<a name="line141"></a>  return this.paletteManager_;
<a name="line142"></a>};
<a name="line143"></a>
<a name="line144"></a>
<a name="line145"></a>/**
<a name="line146"></a> * Returns actions for this palette.
<a name="line147"></a> * @return {Array.&lt;string&gt;} The palette actions.
<a name="line148"></a> */
<a name="line149"></a>goog.ui.equation.Palette.prototype.getActions = function() {
<a name="line150"></a>  return this.actions_;
<a name="line151"></a>};
<a name="line152"></a>
<a name="line153"></a>
<a name="line154"></a>/**
<a name="line155"></a> * Returns the action for a given index.
<a name="line156"></a> * @param {number} index The index of the action to be retrieved.
<a name="line157"></a> * @return {string?} The action for given index, or {@code null} if action is
<a name="line158"></a> *     not found.
<a name="line159"></a> */
<a name="line160"></a>goog.ui.equation.Palette.prototype.getAction = function(index) {
<a name="line161"></a>  return (index &gt;= 0 &amp;&amp; index &lt; this.actions_.length) ?
<a name="line162"></a>      this.actions_[index] : null;
<a name="line163"></a>};
<a name="line164"></a>
<a name="line165"></a>
<a name="line166"></a>/**
<a name="line167"></a> * Handles mouseup events. Overrides {@link goog.ui.Palette#handleMouseUp}
<a name="line168"></a> * by dispatching a {@link goog.ui.equation.PaletteEvent}.
<a name="line169"></a> * @param {goog.events.Event} e Mouse event to handle.
<a name="line170"></a> * @override
<a name="line171"></a> */
<a name="line172"></a>goog.ui.equation.Palette.prototype.handleMouseUp = function(e) {
<a name="line173"></a>  goog.ui.equation.Palette.base(this, &#39;handleMouseUp&#39;, e);
<a name="line174"></a>
<a name="line175"></a>  this.paletteManager_.dispatchEvent(
<a name="line176"></a>      new goog.ui.equation.PaletteEvent(
<a name="line177"></a>          goog.ui.equation.PaletteEvent.Type.ACTION, this));
<a name="line178"></a>};
<a name="line179"></a>
<a name="line180"></a>
<a name="line181"></a>/**
<a name="line182"></a> * Handles mouse out events. Overrides {@link goog.ui.Palette#handleMouseOut}
<a name="line183"></a> * by deactivate the palette.
<a name="line184"></a> * @param {goog.events.BrowserEvent} e Mouse event to handle.
<a name="line185"></a> * @override
<a name="line186"></a> */
<a name="line187"></a>goog.ui.equation.Palette.prototype.handleMouseOut = function(e) {
<a name="line188"></a>  goog.ui.equation.Palette.base(this, &#39;handleMouseOut&#39;, e);
<a name="line189"></a>
<a name="line190"></a>  // Ignore mouse moves between descendants.
<a name="line191"></a>  if (e.relatedTarget &amp;&amp;
<a name="line192"></a>      !goog.dom.contains(this.getElement(), e.relatedTarget)) {
<a name="line193"></a>    this.paletteManager_.deactivate();
<a name="line194"></a>  }
<a name="line195"></a>};
<a name="line196"></a>
<a name="line197"></a>
<a name="line198"></a>/**
<a name="line199"></a> * Handles mouse over events. Overrides {@link goog.ui.Palette#handleMouseOver}
<a name="line200"></a> * by stop deactivating the palette. When mouse leaves the palettes, the
<a name="line201"></a> * palettes will be deactivated after a centain period of time. Reentering the
<a name="line202"></a> * palettes inside this time will stop the timer and cancel the deactivation.
<a name="line203"></a> * @param {goog.events.BrowserEvent} e Mouse event to handle.
<a name="line204"></a> * @override
<a name="line205"></a> */
<a name="line206"></a>goog.ui.equation.Palette.prototype.handleMouseOver = function(e) {
<a name="line207"></a>  goog.ui.equation.Palette.base(this, &#39;handleMouseOver&#39;, e);
<a name="line208"></a>
<a name="line209"></a>  // Ignore mouse moves between descendants.
<a name="line210"></a>  if (e.relatedTarget &amp;&amp;
<a name="line211"></a>      !goog.dom.contains(this.getElement(), e.relatedTarget)) {
<a name="line212"></a>
<a name="line213"></a>    // Stop the timer to deactivate the palettes.
<a name="line214"></a>    this.paletteManager_.stopDeactivation();
<a name="line215"></a>  }
<a name="line216"></a>};
<a name="line217"></a>
<a name="line218"></a>
<a name="line219"></a>
<a name="line220"></a>/**
<a name="line221"></a> * The event that palettes dispatches.
<a name="line222"></a> * @param {string} type Type of the event.
<a name="line223"></a> * @param {goog.ui.equation.Palette} palette The palette that the
<a name="line224"></a> *     event is fired on.
<a name="line225"></a> * @param {Element=} opt_target The optional target of the event.
<a name="line226"></a> * @constructor
<a name="line227"></a> * @extends {goog.events.Event}
<a name="line228"></a> * @final
<a name="line229"></a> */
<a name="line230"></a>goog.ui.equation.PaletteEvent = function(type, palette, opt_target) {
<a name="line231"></a>  goog.events.Event.call(this, type, opt_target);
<a name="line232"></a>
<a name="line233"></a>  /**
<a name="line234"></a>   * The palette the event is fired from.
<a name="line235"></a>   * @type {goog.ui.equation.Palette}
<a name="line236"></a>   * @private
<a name="line237"></a>   */
<a name="line238"></a>  this.palette_ = palette;
<a name="line239"></a>};
<a name="line240"></a>
<a name="line241"></a>
<a name="line242"></a>/**
<a name="line243"></a> * The type of events that can be fired on palettes.
<a name="line244"></a> * @enum {string}
<a name="line245"></a> */
<a name="line246"></a>goog.ui.equation.PaletteEvent.Type = {
<a name="line247"></a>
<a name="line248"></a>  // Take the action that is associated with the palette item.
<a name="line249"></a>  ACTION: &#39;a&#39;
<a name="line250"></a>};
<a name="line251"></a>
<a name="line252"></a>
<a name="line253"></a>/**
<a name="line254"></a> * Returns the palette that this event is fired from.
<a name="line255"></a> * @return {goog.ui.equation.Palette} The palette this event is
<a name="line256"></a> *     fired from.
<a name="line257"></a> */
<a name="line258"></a>goog.ui.equation.PaletteEvent.prototype.getPalette = function() {
<a name="line259"></a>  return this.palette_;
<a name="line260"></a>};
<a name="line261"></a>
<a name="line262"></a>
<a name="line263"></a>
<a name="line264"></a>/**
<a name="line265"></a> * The renderer for palette.
<a name="line266"></a> * @extends {goog.ui.PaletteRenderer}
<a name="line267"></a> * @constructor
<a name="line268"></a> */
<a name="line269"></a>goog.ui.equation.PaletteRenderer = function() {
<a name="line270"></a>  goog.ui.PaletteRenderer.call(this);
<a name="line271"></a>};
<a name="line272"></a>goog.inherits(goog.ui.equation.PaletteRenderer, goog.ui.PaletteRenderer);
<a name="line273"></a>goog.addSingletonGetter(goog.ui.equation.PaletteRenderer);
<a name="line274"></a>
<a name="line275"></a>
<a name="line276"></a>/** @override */
<a name="line277"></a>goog.ui.equation.PaletteRenderer.prototype.getCssClass =
<a name="line278"></a>    function() {
<a name="line279"></a>  return goog.ui.equation.Palette.CSS_CLASS;
<a name="line280"></a>};
<a name="line281"></a>
<a name="line282"></a>
<a name="line283"></a>/**
<a name="line284"></a> * Returns the CSS class name for the palette item.
<a name="line285"></a> * @return {string} The CSS class name of the palette item.
<a name="line286"></a> */
<a name="line287"></a>goog.ui.equation.PaletteRenderer.prototype.getItemCssClass = function() {
<a name="line288"></a>  return this.getCssClass() + &#39;-item&#39;;
<a name="line289"></a>};
</pre>


</body>
</html>
